const mysql = require('mysql')
const config = require('./config')

module.exports = function (sql, sqlParams) {
    return new Promise(function (resolve, reject) {
        var connection = mysql.createConnection({
          host     : config.host,
          user     : config.user,
          password : config.password,
          port     : config.port,
          database : config.database
        })
        connection.connect()
        connection.query(sql, sqlParams, function (err,result) {
            connection.end()
            if(err) { console.error('Error:'+ err ) ; reject(err)}
            else resolve(result)
        })
    })
}
